package com.mdb.open.trade.resource;

import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.trade.domain.dto.product.SetWhiteListDto;
import com.mdb.open.trade.domain.dto.product.SignDto;
import com.mdb.open.trade.domain.dto.product.VerifySignDto;
import com.mdb.open.trade.domain.vo.product.CustProdConfigVo;
import com.mdb.open.trade.facade.CustProdFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author liuyi
 * @date 2019/06/14
 **/
@RestController
@RequestMapping("product/auth")
@Api(tags = "产品权限相关接口")
@ApiIgnore
public class ProductAuthResource extends SuperResources {

    @Autowired
    private CustProdFacade custProdFacade;

    @LogAnnotation
    @ApiOperation("根据appId获取客户配置")
    @GetMapping("/config/{appId}")
    @ApiIgnore
    public ResultEx<CustProdConfigVo> getAppConfigByAppId(@PathVariable("appId") String appId) {
        return custProdFacade.getAppConfigByAppId(appId);
    }

    @LogAnnotation
    @ApiOperation("根据appId，ip白名单校验")
    @GetMapping("/check_whitelist/{appId}/{ip}")
    @ApiIgnore
    public ResultEx checkWhitelist(@PathVariable("appId") String appId, @PathVariable("ip") String ip) {
        return custProdFacade.checkWhitelist(appId, ip);
    }

    @LogAnnotation
    @ApiOperation("加签")
    @PostMapping("/sign")
    @ApiIgnore
    public ResultEx<String> sign(@RequestBody SignDto dto) {
        return custProdFacade.sign(dto);
    }

    @LogAnnotation
    @ApiOperation("验签")
    @PostMapping("/verify_sign")
    @ApiIgnore
    public ResultEx checkSign(@RequestBody VerifySignDto dto) {
        return custProdFacade.checkSign(dto);
    }

    @LogAnnotation
    @ApiOperation("产品白名单设置")
    @PostMapping("/set_whitelist")
    @ApiIgnore
    public ResultEx<Boolean> setWhitelist(@RequestBody SetWhiteListDto dto) {
        return custProdFacade.setWhitelist(dto);
    }
}
